/**
 * 单例模式
 */

class SingleObject {
    log() {
        console.log('log...')
    }
}

SingleObject.getInstance = (function() {
    let instance = null
    return function () {
        if(!instance) {
            instance = new SingleObject()
        }
        return instance
    }
})()

function test() {
    let s1 = SingleObject.getInstance()
    s1.log()
    let s2 = SingleObject.getInstance()
    console.log('s1 === s2 的结果是', s1 === s2)
}

console.log('----------------单例模式-------------------')
test()
